# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: inkyu

from coin.strategy.mm.subscription import SubscriptionRequest

from coin.strategy.mm.binance.order_subsystem import BinanceOrderSubsystem
from coin.strategy.mm.bitfinex.order_subsystem import BitfinexOrderSubsystem
from coin.strategy.mm.bitflyer_v1.order_subsystem import BitflyerOrderSubsystem
from coin.strategy.mm.bithumb.order_subsystem import BithumbOrderSubsystem
from coin.strategy.mm.bitmex.order_subsystem import BitmexOrderSubsystem
from coin.strategy.mm.hitbtc_v2.order_subsystem import HitbtcOrderSubsystem
from coin.strategy.mm.huobi.order_subsystem import HuobiOrderSubsystem
from coin.strategy.mm.huobi_futures.order_subsystem import HuobiFuturesOrderSubsystem
from coin.strategy.mm.kraken.order_subsystem import KrakenOrderSubsystem
from coin.strategy.mm.kraken_futures.order_subsystem import KrakenFuturesOrderSubsystem
from coin.strategy.mm.quoinex_v2.order_subsystem import QuoinexOrderSubsystem
from coin.strategy.mm.upbit.order_subsystem import UpbitOrderSubsystem
from coin.strategy.mm.okex_futures_swap.order_subsystem import OkexFuturesSwapOrderSubsystem
from coin.strategy.mm.okex.order_subsystem import (
    OkexOrderSubsystem,
    OkexOrderSubsystemV3,
)
from coin.strategy.mm.okex_futures.order_subsystem import (
    OkexFuturesOrderSubsystem,
    OkexFuturesOrderSubsystemV3,
)
from coin.strategy.mm.gdax.order_subsystem import GdaxOrderSubsystem
from coin.strategy.mm.bitstamp_v2.order_subsystem import BitstampOrderSubsystem
from coin.strategy.mm.korbit_v1.order_subsystem import KorbitOrderSubsystem
from coin.strategy.mm.coinone_v2.order_subsystem import CoinoneOrderSubsystem
from coin.strategy.mm.deribit_v2.order_subsystem import DeribitFuturesOrderSubsystem
from coin.strategy.mm.gopax.order_subsystem import GopaxOrderSubsystem
from coin.strategy.mm.binance_futures_swap.order_subsystem import BinanceSwapFuturesOrderSubsystem
from coin.strategy.mm.uniswap_v3.order_subsystem import UniswapV3OrderSubsystem
from coin.strategy.mm.uniswap_v3_arbitrum.order_subsystem import UniswapV3ArbitrumOrderSubsystem
from coin.strategy.mm.uniswap_v2.order_subsystem import UniswapV2OrderSubsystem


def get_live_env_cls(sub_key):
  assert type(sub_key) == SubscriptionRequest, type(sub_key)
  feed_subsystem_map = {
      SubscriptionRequest('Spot', 'Binance', None): BinanceOrderSubsystem,
      SubscriptionRequest('Spot', 'Binance', 'snapshot'): BinanceOrderSubsystem,
      SubscriptionRequest('Spot', 'Binance', 'l1_realtime'): BinanceOrderSubsystem,
      SubscriptionRequest('Spot', 'Bitfinex', None): BitfinexOrderSubsystem,
      SubscriptionRequest('Margin', 'Bitfinex', None): BitfinexOrderSubsystem,
      SubscriptionRequest('Spot', 'Bitflyer', 'v1'): BitflyerOrderSubsystem,
      SubscriptionRequest('Spot', 'Bitflyer', None): BitflyerOrderSubsystem,
      SubscriptionRequest('Spot', 'Bithumb', None): BithumbOrderSubsystem,
      SubscriptionRequest('Spot', 'Hitbtc', None): HitbtcOrderSubsystem,
      SubscriptionRequest('Spot', 'Huobi', None): HuobiOrderSubsystem,
      SubscriptionRequest('Spot', 'Okex', None): OkexOrderSubsystemV3,
      SubscriptionRequest('Spot', 'Okex', 'v1'): OkexOrderSubsystem,
      SubscriptionRequest('Spot', 'Okex', 'v3'): OkexOrderSubsystemV3,
      SubscriptionRequest('Spot', 'Kraken', None): KrakenOrderSubsystem,
      SubscriptionRequest('Spot', 'Upbit', None): UpbitOrderSubsystem,
      SubscriptionRequest('Spot', 'Quoinex', None): QuoinexOrderSubsystem,
      SubscriptionRequest('Spot', 'Quoinex', 'single_channel'): QuoinexOrderSubsystem,
      SubscriptionRequest('Spot', 'Gdax', None): GdaxOrderSubsystem,
      SubscriptionRequest('Spot', 'Bitstamp', None): BitstampOrderSubsystem,
      SubscriptionRequest('Spot', 'Korbit', None): KorbitOrderSubsystem,
      SubscriptionRequest('Spot', 'Coinone', None): CoinoneOrderSubsystem,
      SubscriptionRequest('Spot', 'Gopax', None): GopaxOrderSubsystem,
      SubscriptionRequest('Futures', 'Bitflyer', 'v1'): BitflyerOrderSubsystem,
      SubscriptionRequest('Futures', 'Bitflyer', None): BitflyerOrderSubsystem,
      SubscriptionRequest('Futures', 'Bitmex', None): BitmexOrderSubsystem,
      SubscriptionRequest('Futures', 'Okex', None): OkexFuturesOrderSubsystemV3,
      SubscriptionRequest('Futures', 'Okex', 'v1'): OkexFuturesOrderSubsystem,
      SubscriptionRequest('Futures', 'Okex', 'v3'): OkexFuturesOrderSubsystemV3,
      SubscriptionRequest('Futures', 'Okex', 'v3_swap'): OkexFuturesSwapOrderSubsystem,
      SubscriptionRequest('Futures', 'Okex', 'v3_realtime'): OkexFuturesOrderSubsystemV3,
      SubscriptionRequest('Futures', 'Huobi', None): HuobiFuturesOrderSubsystem,
      SubscriptionRequest('Futures', 'Kraken', None): KrakenFuturesOrderSubsystem,
      SubscriptionRequest('Futures', 'Deribit', None): DeribitFuturesOrderSubsystem,
      SubscriptionRequest('Futures', 'Binance', None): BinanceSwapFuturesOrderSubsystem,
      SubscriptionRequest('Spot', 'Uniswap', 'v3'): UniswapV3OrderSubsystem,
      SubscriptionRequest('Spot', 'Uniswap', 'v3-arbitrum'): UniswapV3ArbitrumOrderSubsystem,
      SubscriptionRequest('Spot', 'Uniswap', 'v2'): UniswapV2OrderSubsystem,
  }
  return feed_subsystem_map[sub_key]


def create_live_env_instance(env_cls,
                             currencies,
                             trade_products,
                             og_trade_key,
                             og_params=None,
                             init_og_after=None,
                             ioloop=None,
                             queue=None,
                             flow_sub=None,
                             og_log_callback=None,
                             logger=None):
  live_env = env_cls(currencies,
                     trade_products,
                     og_trade_key,
                     og_params=og_params,
                     init_og_after=init_og_after,
                     ioloop=ioloop,
                     queue=queue,
                     flow_sub=flow_sub,
                     og_log_callback=og_log_callback)
  return live_env
